package com.zhihu.jjn.demoproject.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhihu.jjn.demoproject.entity.User;
import com.zhihu.jjn.demoproject.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author Jiang Jining
 * @date 2020/11/1 11:12
 */
@Service
public class UserServiceImpl implements UserService {
    @Override
    public JSONObject registerUser(User user) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        user.setRegistered(true);
        user.setRegisterTime(new Date());
        user.setUpdateTime(new Date());
        String string = objectMapper.writeValueAsString(user);
        return JSON.parseObject(string);
    }
}
